﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ConsoleApplication2
{
    public class Serialize<T>
    {
        //Serialize and saves the object in the direction last
        public void serializeGame(T value, string path)
        {
            var xmlWriter = XmlWriter.Create(path);
            var serializer = new XmlSerializer(typeof(T));
            serializer.Serialize(xmlWriter, value);
            xmlWriter.Close();
            
        }

        //Deserialize and load the object in the direction
        public T DeserializeGame(String path)
        {
            var xmlReader = XmlReader.Create(path);
            var serializer = new XmlSerializer(typeof (T));
            T value = (T)serializer.Deserialize(xmlReader);
            xmlReader.Close();
            return value;
        }
    }
}


